from sqlmodel import Session
from models import Hero,Team
from db import init_db,get_db,close_db

def creare_heroes(session:Session):
    """ 创建英雄"""
    team1 = Team(name="A")
    team2 = Team(name="B")
    hero1 = Hero(name="hero1",age=18,teams=[team1,team2])
    hero2 = Hero(name="hero2",age=18,teams=[team2])
    session.add(team1)
    session.add(team2)
    session.add(hero1)
    session.add(hero2)
    session.commit()
    session.refresh(hero1)
    session.refresh(hero2)

    print(hero1.teams)
    print(hero2.teams)

def main():
    init_db()
    with get_db() as session:
        creare_heroes(session)
    close_db()

if __name__ == "__main__":
   main()